////////////////////////////////////////////////////////////////////////////////
// Copyright 2010 Michael Schmalle - Teoti Graphix, LLC
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0 
// 
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and 
// limitations under the License
// 
// Author: Michael Schmalle, Principal Architect
// mschmalle at teotigraphix dot com
////////////////////////////////////////////////////////////////////////////////

package org.teotigraphix.swizplugin.services
{

import flash.events.IEventDispatcher;

import org.teotigraphix.swizplugin.api.IExecutableRequest;
import org.teotigraphix.swizplugin.bundles.IBundle;

/**
 * The <strong>IBundleService</strong> manages <code>IBundle</code> instances.
 * 
 * @author Michael Schmalle
 * @copyright Teoti Graphix, LLC
 * @productversion 1.0
 */
public interface IBundleService extends IEventDispatcher
{
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Returns whether the bundle service is active, meaining it has fully
	 * started up.
	 */
	function get active():Boolean;
	
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Starts the bundle service.
	 */
	function start():void;
	
	/**
	 * Adds an <code>IBundle</code> to the bundle service.
	 * 
	 * @param bundle The <code>IBundle</code> to add.
	 * @event org.teotigraphix.swizplugin.events.BundleServiceEvent#BUNDLE_ADD
	 */
	function addBundle(bundle:IBundle):void;
	
	/**
	 * Removes an <code>IBundle</code> from the bundle service.
	 * 
	 * @param bundle The <code>IBundle</code> to remove.
	 * @event org.teotigraphix.swizplugin.events.BundleServiceEvent#BUNDLE_REMOVE
	 */
	function removeBundle(bundle:IBundle):void;
	
	/**
	 * Returns an <code>IBundle</code> by <code>bundleID</code>.
	 * 
	 * @param bundleID The <code>IBundle.bundleID</code>.
	 * @return An <code>IBundle</code> if found, <code>null</code> if not.
	 */
	function getBundle(bundleID:int):IBundle;
	
	/**
	 * Returns an <code>IBundle</code> by <code>symbolicName</code>.
	 * 
	 * @param symbolicName The <code>IBundle.symbolicName</code>.
	 * @return An <code>IBundle</code> if found, <code>null</code> if note.
	 */
	function getBundleByName(symbolicName:String):IBundle;
	
	/**
	 * Returns all <code>IBundle</code> instances in the bundle service.
	 * 
	 * <p>The return Array is a copy of the serivce's bundle collection.</p>
	 * 
	 * @return An Array of <code>IBundle</code> instances, <code>null</code>
	 * if none.
	 */
	function getBundles():Array;
	
	/**
	 * Loads a bundle from the url given.
	 * 
	 * @param url A String url location to load a bundle from.
	 * 
	 * @event org.teotigraphix.swizplugin.events.BundleServiceEvent#BUNDLE_LOAD_REQUESTED
	 * @event org.teotigraphix.swizplugin.events.BundleServiceEvent#BUNDLE_LOAD_COMPLETE
	 */
	function loadBundle(url:String):void;
	
	/**
	 * Loads a class from the bundle.
	 * 
	 * <p>Dispatches event when class is loaded from getDefinition() or
	 * the class loader.</p>
	 * 
	 * @param className A String indiacting the Class to load.
	 */
	function loadClass(bundle:IBundle, className:String):IExecutableRequest;
	
	/**
	 * Creates and returns an <code>IExecutableRequest</code> token.
	 * 
	 * @return A <code>IExecutableRequest</code> token.
	 */
	function createExecutableRequest():IExecutableRequest;
}
}